<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Structure of a Constraint Program
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial054.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial053.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial056.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc116">8.2</A>&nbsp;&nbsp;Structure of a Constraint Program</H2>
The typical top-level structure of a constraint program is

	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCCCFF">
	<BLOCKQUOTE CLASS="quote"><PRE>
solve(Variables) :-
        read_data(Data),
        setup_constraints(Data, Variables),
        labeling(Variables).
</PRE></BLOCKQUOTE></TD>
</TR></TABLE>
where <CODE>setup_constraints/2</CODE> contains the problem model. It creates the
variables and the constraints over the variables.
This is often, but not necessarily, deterministic.
The <CODE>labeling/1</CODE> predicate is the search part of the program that
attempts to find solutions by trying all instantiations for the
variables. This search is constantly pruned by constraint propagation.<BR>
<BR>
The above program will find all solutions.
If the best solution is wanted, a branch-and-bound
procedure can be wrapped around the search component of the program:

	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCCCFF">
	<BLOCKQUOTE CLASS="quote"><PRE>
solve(Variables) :-
        read_data(Data),
        setup_constraints(Data, Variables, Objective),
        branch_and_bound:minimize(labeling(Variables), Objective).
</PRE></BLOCKQUOTE></TD>
</TR></TABLE>
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>&#8857;</B><DD CLASS="dd-description"> <FONT COLOR="#9832CC">The <EM>branch_and_bound</EM> library provides generic predicates 
that support optimization in conjunction with any ECL</FONT><SUP><FONT COLOR="#9832CC"><I>i</I></FONT></SUP><FONT COLOR="#9832CC">PS</FONT><SUP><FONT COLOR="#9832CC"><I>e</I></FONT></SUP><FONT COLOR="#9832CC"> solver. 
Section&nbsp;</FONT><A HREF="tutorial087.html#secbboptsearch"><FONT COLOR="#9832CC">12.1.2</FONT></A><FONT COLOR="#9832CC"> discusses these predicates.</FONT>
</DL>

<HR>
<A HREF="tutorial054.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial053.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial056.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
